/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2025-03-10 10:18:46
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-03-15 23:08:34
 * @FilePath: /backend/shorthand-modules/shorthand-modules-content/src/main/java/com/angus/modules/content/controller/work/PayPalController.java
 */
package com.angus.modules.content.controller.work;

import com.angus.common.core.web.domain.AjaxResult;
import com.angus.modules.content.dto.PayPalOrderPayDto;
import com.angus.modules.content.service.PayPalService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author liyanan
 * @date 2025/03/03 10:10 PM
 * @description
 */
@RestController
@RequestMapping("/paypal")
public class PayPalController {

    @Resource
    private PayPalService payPalService;

    /**
     * 支付
     * @param dto 支付参数
     * @return 支付结果
     */
    @PostMapping("/pay")
    public AjaxResult payPalPay(@RequestBody PayPalOrderPayDto dto) {
        return payPalService.payPalPay(dto);
    }

    /**
     * 支付成功回调
     * @param paymentId 支付编号
     * @param payerId 支付人编号
     * @return 支付结果
     */
    @GetMapping("/success")
    public AjaxResult paymentSuccess(@RequestParam("paymentId") String paymentId, @RequestParam("PayerID") String payerId) {
        return  payPalService.paymentSuccess(paymentId, payerId);
    }

    /**
     * 支付取消回调
     * @param paymentId 支付编号
     * @param payerId 支付人编号
     * @return 支付结果
     */
    @GetMapping("/cancel")
    public AjaxResult paymentCancel(@RequestParam("paymentId") String paymentId, @RequestParam("PayerID") String payerId) {
        return payPalService.paymentCancel(paymentId, payerId);
    }
}
